home *** CD-ROM | disk | FTP | other *** search
- #include "SFConvert.h"
- #include <stdio.h>
- #include <unix.h>
- #include <string.h>
- #include <math.h>
- #include <SANE.h>
- #include "SDtype.h"
-
-
-
- extern long TotalSamps;
- extern CursHandle watchCurs;
- extern long SampleRate;
- extern double MaxSample;
- extern double MinSample;
- extern long fileSize;
- extern ioParam myIOParmBlk;
- extern ioParam NewParmBlk;
- extern int SFOUTPUTtype;
- extern Boolean SDnoResource;
- extern OSErr theErr;
- extern long RecLength;
- extern int nrec;
-
-
- void DoOSErrorAlert(Str255, Str255);
-
- Boolean InterleavedToSD1(void);
- Boolean InterleavedToSD2(void);
- Boolean InterleavedToCHUNKY(void);
- Boolean InterleavedToAIFF(void);
- Boolean InterleavedToFloat(void);
-
-
- Boolean InterleavedToSD1()
- {
- return(FALSE);
- }
- Boolean InterleavedToSD2()
- {
- return(FALSE);
- }
- Boolean InterleavedToCHUNKY()
- {
- return(FALSE);
- }
- Boolean InterleavedToAIFF()
- {
- return(FALSE);
- }
- Boolean InterleavedToFloat()
- {
- register long i;
- register double offset;
- register double scalefactor;
- register double x;
- Str255 mess;
- unsigned int *theIbuf, *Iptr;
- float *sp, *SampBuf;
- long nBytes;
- long nSamps;
- long bytesLeft;
- long sampBufsz;
-
-
-
- RecLength = (long)(16384);
- nrec = 0;
- SetProgressDialog();
-
- TotalSamps = fileSize / sizeof(int);
-
- sampBufsz = RecLength / sizeof(float);
- theIbuf = (unsigned int *)NewPtr(sizeof(int) * sampBufsz);
- SampBuf = (float *)NewPtr( sizeof(float) * sampBufsz);
-
-
- offset = fabs(MinSample);
- scalefactor = SAMPMAX / (offset + MaxSample);
-
- bytesLeft = fileSize;
-
- myIOParmBlk.ioPosMode = fsAtMark;
- myIOParmBlk.ioPosOffset = NIL;
-
- NewParmBlk.ioPosMode = fsAtMark;
- NewParmBlk.ioPosOffset = NIL;
-
-
- while ( bytesLeft > 0L ) {
- if ( bytesLeft > RecLength )
- nBytes = RecLength;
- else
- nBytes = bytesLeft;
-
- myIOParmBlk.ioBuffer = (Ptr)theIbuf;
- myIOParmBlk.ioReqCount = nBytes;
- theErr = PBRead(&myIOParmBlk, FALSE);
- if (theErr != noErr ) {
- if ( theErr == eofErr )
- DoOSErrorAlert("\pEnd of file reached in read form MACread_set", NIL);
- }
- nBytes = myIOParmBlk.ioActCount;
- nSamps = nBytes / sizeof(int);
- for ( i = 0, Iptr = theIbuf, sp = SampBuf; i < nSamps; i++ ) {
- *sp++ = ((*Iptr++ + offset ) * scalefactor);
- }
-
- /* write it out */
- NewParmBlk.ioReqCount = (long)(nSamps * sizeof(float));
- NewParmBlk.ioBuffer = (Ptr)SampBuf;
- if ( (theErr = PBWrite(&NewParmBlk, FALSE)) != noErr ) {
- DoOSErrorAlert("\pError writing to sample file", NIL);
- }
- if ( NewParmBlk.ioActCount != (long)(nSamps * sizeof(float)) ) {
- DoOSErrorAlert("\pError writing to sample file, wrote wrong number of bytes", NIL);
- }
-
- nrec++;
- if ( !UpdateProgressDialog() ) {
- DisposPtr((Ptr)SampBuf);
- DisposPtr((Ptr)theIbuf);
- DisposeProgDialog();
- InitCursor();
- return(FALSE);
- }
- bytesLeft -= nBytes;
- }
- DisposPtr((Ptr)SampBuf);
- DisposPtr((Ptr)theIbuf);
- DisposeProgDialog();
- InitCursor();
- return(TRUE);
- }
-